package com.cskaoyan.controller.vx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.vxBo.CouponWxBO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.wxPo.MarketCoupon;
import com.cskaoyan.bean.po.wxPo.MarketCouponUser;
import com.cskaoyan.bean.po.wxPo.MarketUser;
import com.cskaoyan.bean.vo.vxVo.CouponVO;
import com.cskaoyan.bean.vo.vxVo.CouponWxVO;
import com.cskaoyan.service.vx.CouponWxService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("wx/coupon")
public class WxCouponController {
    @Autowired
    CouponWxService couponService;


    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam){
        CouponVO couponVO = couponService.selectCoupon(baseParam);
        return BaseRespVo.ok(couponVO);
    }

    @RequestMapping("mylist")
    public BaseRespVo mylist(BaseParam baseParam,Short status){
        CouponWxVO couponWxVO = couponService.selectMyCoupon(baseParam,status);
        return BaseRespVo.ok(couponWxVO);
    }

    @RequestMapping("receive")
    public BaseRespVo receive(@RequestBody MarketCouponUser marketCouponUser){
        MarketCouponUser marketCouponUser1 = couponService.insertCoupon(marketCouponUser);
        return BaseRespVo.ok(null);
    }
    @RequestMapping("exchange")
    public BaseRespVo exchange(@RequestBody MarketCoupon marketCoupon){
       /*MarketCoupon marketCoupon1 =*/
        int count = couponService.ExchangeCoupon(marketCoupon);
//        if(!(marketCoupon.getCode().equals(marketCoupon1.getCode()))){
//            return BaseRespVo.err("错误",200);
//        }
        if(count == 1){
            return BaseRespVo.ok(null);
        }else {
            return BaseRespVo.err("错误",200);
        }

    }

    //待测试
    @RequestMapping("selectlist")
    public BaseRespVo selectlist(BaseParam baseParam,Integer cartId,Integer grouponRulesId){
        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        CouponWxVO couponWxBO = couponService.selectOtherSelectList(baseParam, cartId, grouponRulesId, marketUser.getId());
        return BaseRespVo.ok(couponWxBO);
    }

}
